package com.train.member.facade;

import cn.hutool.core.bean.BeanUtil;
import com.train.common.resp.CommonResp;
import com.train.member.dto.MemberLoginDTO;
import com.train.member.dto.MemberSendSmsDTO;
import com.train.member.req.MemberLoginReq;
import com.train.member.req.MemberSendSmsReq;
import com.train.member.resp.CaptchaResp;
import com.train.member.resp.LoginResp;
import com.train.member.resp.MemberSendSmsResp;
import com.train.member.resp.UserInfoResp;
import com.train.member.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("member")
public class MemberFacade {

    private final MemberService memberService;

    /**
     * 用户手机号注册
     * @param memberSendSmsReq
     */
    @PostMapping("sendSms")
    public CommonResp sendSms(@RequestBody MemberSendSmsReq memberSendSmsReq) {
        MemberSendSmsDTO memberSendSmsDTO = BeanUtil.copyProperties(memberSendSmsReq, MemberSendSmsDTO.class);
        MemberSendSmsResp sendSmsResp = memberService.sendSms(memberSendSmsDTO);
        return CommonResp.ok(sendSmsResp);
    }

    /**
     * 用户登录
     * @param memberLoginReq
     * @return
     */
    @PostMapping("login")
    public CommonResp login(@RequestBody MemberLoginReq memberLoginReq) {
        MemberLoginDTO memberLoginDTO = BeanUtil.copyProperties(memberLoginReq, MemberLoginDTO.class);
        LoginResp loginResp = memberService.login(memberLoginDTO);
        return CommonResp.ok(loginResp);
    }

    /**
     * 获取图形验证码
     * @return
     */
    @PostMapping("captcha")
    public CommonResp captcha() {
        CaptchaResp captchaResp = memberService.captcha();
        return CommonResp.ok(captchaResp);
    }

    @PostMapping("user-info")
    public CommonResp userInfo() {
        UserInfoResp userInfoResp = memberService.getUserInfo();
        return CommonResp.ok(userInfoResp);
    }
}
